<template>
  <view>
    <view class="list flex flex-col justify-center items-center">
    	<view class="flex flex-col justify-start item" :style="styleBox" @touchend="handleTouchEnd"  v-for="(item,index) in list" :key="index"  @click="$util.Tips(`/subpageB/choujiang_detail/choujiang_detail?id=${item.activityId}`)">
    		<!-- 普通抽奖 -->
    		<template v-if="item.type==1">
    
    			<image v-if="item.prizes[0].imageUrl&&item.prizes[0].imageUrl!=''" class="banner"  :src="item.prizes[0].imageUrl" mode="aspectFill"></image>
    			<view class="info flex flex-col justify-start">
					<view class="flex flex-row justifity-between items-center">
						<view class="c_0 f_30 title" style="flex: 1">{{item.activityTitle}}</view>
						<view class="c_9 f_28" style="width: 200rpx">{{item.submitTime}}</view>
					</view>
    				
    				<view class="tag flex flex-row justify-start items-center"  v-if="item.showtype.length>0">
    					<text v-for="(item1,index1) in item.showtype" :key="index1">{{item1}}</text>
    
    				</view>
    				<template v-if="item.status == 1">
    				  <view class="flex flex-row items-center mt_10">
    				  <!-- 判断是否为今天  是的话显示倒计时 -->
    				  <template v-if="isToday(item.openTime)">
    				  	 <text class="f_22  c_f bg-red kjbtn">即将开奖</text>
    				  	<liu-countdown ref="countdown" mode="1" :showDays="false"  auto :endDate="item.openTime"></liu-countdown>
    
    				  </template>
    				  <template v-else>
    				  	<view class="f_24 c_5a">{{item.openTime}} 自动开奖</view>
    				  </template>
    				    <text v-if="item.minPeople-item.recordCount>0" class="f_26 c_9"
    				      >,还差<text class="ml5 red mr5">{{ item.minPeople-item.recordCount}}</text
    				      >人</text
    				    >
    				  </view>
    				</template>
    				<view class="autho_info flex flex-row justify-between w100 items-center">
    					<view class="autho_img flex flex-row justify-start items-center">
    						<image v-if="item.merchant.logo" :src="item.merchant.logo" mode="widthFix" class="autho"></image>
    						<image v-else src="@/static/logo.png" mode="aspectFit" class="autho"></image>
    
    						<image src="@/static/index/v.png" mode="widthFix" class="v-icon"></image>
    						<text class="f_24 c_5a">{{item.merchant.name?item.merchant.name:'平台'}}</text>
    					</view>
    					<view class="auth_btn f_30 c_f" v-if="item.status==1">
    						点击参与
    					</view>
    
    					<view class="auth_btn f_30 c_f" v-if="item.status==2">
    						去抽奖
    					</view>
    				</view>
    			</view>
    
    		</template>
    		<!-- 红包抽奖 -->
    		<template v-else>
    			<!-- <text v-if="item.money" class="money">￥{{item.money}}</text>
    			<image class="banner"  src="@/static/index/money.png" mode="widthFix"></image> -->
    			<view class="info flex flex-col justify-start">
    				<view class="flex flex-row justify-between items-center">
    					<view class="c_0 f_30 title" style="flex: 1">{{item.activityTitle}}</view>
						<view class="auth_btn f_30 red" v-if="item.status==-1">
							待开奖
						</view>
    					<view class="auth_btn f_30 orange" v-if="item.status==0">
    						待兑奖
    					</view>
    					<view class="auth_btn f_30 orange" v-if="item.status==1">
    						已参与
    					</view>
    					    
    					<view class="auth_btn f_30 red" v-if="item.status==2">
    						开奖中
    					</view>
    					<view class="auth_btn f_30 green " v-if="item.status==3">
    						已完成
    					</view>
    					<view class="auth_btn f_30 c_52 " v-if="item.status==4">
    						已取消
    					</view>
    					<view class="auth_btn f_30 c_52 " v-if="item.status==5">
    						已过期
    					</view>
    				</view>
    
    				<view class="autho_info flex flex-row justify-between w100 items-center">
    					<view class="autho_img flex flex-row justify-start items-center">
    						<image v-if="item.merchant.logo" :src="item.merchant.logo" mode="widthFix" class="autho"></image>
    						<image v-else src="@/static/logo.png" mode="aspectFit" class="autho"></image>
    
    						<image src="@/static/index/v.png" mode="widthFix" class="v-icon"></image>
    						<text class="f_24 c_5a">{{item.merchant.name?item.merchant.name:'平台'}}</text>
    					</view>
						<view class="c_9 f_28">{{getTimeAgo(item.submitTime)}}</view>
						
    				</view>
    			</view>
    		</template>
    
    	</view>
    
    </view>
	<ListFooter :loadtitle="loadtitle"></ListFooter>
  </view>
</template>

<script>
 import { getTimeAgo } from '../../utils/index'
 
 import {mapGetters} from "vuex";
 import {
 	drawRcord,
 } from '@/api/activity.js';
import ListFooter from '../../components/listFooter/listFooter.vue';
 export default {
    computed: mapGetters(['isLogin', 'chatUrl', 'userInfo', 'uid']),
	components: {ListFooter},
    data() {
        return {
            list: [],
            loading: false,
            loadend: false,
            loadtitle: '加载更多',
            page: 1,
            limit: 10,
        };
    },
    onLoad() {
        this.getdraw();
    },
    onReachBottom: function () {
        this.page++;
        this.getdraw();
    },
    onPullDownRefresh() {
        this.page = 1;
		this.loadend = false
		this.list = []
        this.getdraw();
        setTimeout(function () {
            uni.stopPullDownRefresh();
        }, 1000);
    },
    methods: {
        // 动态显示时间值
        getTimeAgo(dateTime) {
            return getTimeAgo(dateTime);
        },
        longpressClick() {
            this.styleBox = 'background-color: #dcdcdc;';
        },
        handleTouchEnd() {
            this.styleBox = 'background-color: #ffffff;';
        },
        //判断是否为今天
        isToday(e) {
            if (!e) {
                return false;
            }
            let date = new Date(e.replace(/-/g, '/'));
            const today = new Date();
            return date.getDate() === today.getDate() &&
                date.getMonth() === today.getMonth() &&
                date.getFullYear() === today.getFullYear();
        },
        gettype(item) {
            let arr = [];
            item.map((e, i) => {
                if (e.prizeType == 1) {
                    if (e.receiveType == 1) {
                        arr.push('物流');
                    }
                    else if (e.receiveType == 2) {
                        arr.push('自提');
                    }
                }
            });
            arr = [...new Set(arr)];
            return arr;
        },
        comtime(time) {
            const now = new Date().getTime();
            const futureDate = new Date(time.replace(/-/g, '/')).getTime();
            const countdown = futureDate - now;
            return countdown;
        },
        getdraw() {
            if (this.loading)
                return;
            if (this.loadend)
                return;
            this.loading = true;
            this.loadtitle = "";
			uni.showLoading({
				title: '加载中...'
			})
            let data = {
                page: this.page,
                uid: this.uid,
                limit: this.limit
            };
			
            drawRcord(data).then(res => {
				uni.hideLoading()
                let list = res.data.list;
                let loadend = list.length < this.limit;
                this.list = this.list.concat(list);
                this.loadend = loadend;
                this.loading = false;
                this.loadtitle = loadend ? "到底啦，没有数据了~" : "加载更多";
            }).catch(err => {
                this.loading = false;
                this.loadtitle = '加载更多';
            });
        }
    },
    components: { ListFooter }
}
</script>

<style  lang="scss">
	.loadingicon{
		padding-bottom: 40rpx;
	}
	.list{
		width: 710rpx;
		margin: 20rpx;
		.kjbtn{
			padding: 5rpx 10rpx;
			border-radius: 6rpx;
			margin-right: 10rpx;
		}
		.item{
			width: 100%;
			border-radius: 20rpx;
			background: #fff;
			margin-top: 25rpx;
			overflow: hidden;
			position: relative;
			.money{
				position: absolute;
				width: 100%;
				text-align: center;
				left: 0;
				top:225rpx;
				font-size: 36rpx;
				color:#ffffc1 ;
				font-weight: bold;
			}
			.banner{
				width: 710rpx;
				height: 360rpx
			}
			.tag{
				margin-top: 10rpx;
				text{
					border-radius: 6rpx;
					background: #FFF6F6;
					font-size: 22rpx;
					color:#DF4B43;
					margin-right: 10rpx;
					padding:5rpx 10rpx;
					border-radius: 5rpx;
				}
			}
			.autho_img{
				position: relative;
				.autho{
					width:50rpx;
					height: 50rpx;
					border-radius: 50rpx;
					margin-right: 10rpx;

				}
				.v-icon{
					width: 21rpx;
					height: 21rpx;
					position: absolute;
					left: 40rpx;
        bottom: 0
				}
			}
			.info{
				width: 100%;
				padding: 20rpx;
				box-sizing: border-box;
			}
		}
	}
	.auth_btn{
		display: flex;
		padding: 20rpx 0rpx;
		justify-content: center;
		align-items: center;
		gap: 10rpx;
		border-radius: 50rpx;
    width: 200rpx;
	//	border: 4rpx solid #F3D7D4;
		//background: linear-gradient(90deg, #FF783E 1.9%, #ED2B00 98.1%);
	}
	.auth_btn_hui{
		display: flex;
		padding: 20rpx 0rpx;
		justify-content: center;
		align-items: center;
		gap: 10rpx;
		border-radius: 50rpx;
		border: 4rpx solid #F3D7D4;
		background: #999;
	}
</style>
